//
//  FMViewController.m
//  FMPickerView
//
//  Created by zhoufaming251@163.com on 06/30/2020.
//  Copyright (c) 2020 zhoufaming251@163.com. All rights reserved.
//

#import "FMViewController.h"
#import <FMPickerView.h>
#import <objc/runtime.h>

@interface FMViewController ()

@end

@implementation FMViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [FMPickerConfigure shareConfigure].backgroundColor = [UIColor blackColor];
    [FMPickerConfigure shareConfigure].textColor = [UIColor whiteColor];
    
//    FMPickerConfigure *con = [[FMPickerConfigure shareConfigure] copy];
//    con.magnifierLineColor = [UIColor redColor];
//    con.textColor = [UIColor redColor];
//    con.highlightColor = [UIColor blueColor];
//    FMPickerDataView *picker = [[FMPickerDataView alloc] initWithFrame:CGRectMake(0, 0, 375, 375) configure:con];
//    
//    [self.view addSubview:picker];
//    [picker showTitle:@"不联动" items:@[@[@"1", @"2", @"3"], @[@"3", @"3", @"1", @"6"]] showText:^NSString * _Nullable(NSInteger component, id  _Nonnull obj) {
//        return obj;
//    } complete:^(NSArray * _Nonnull selects, NSDictionary * _Nonnull selectRows) {
//        
//    }];
    
    
    unsigned int outCount;

    int i;

    objc_property_t *pProperty = class_copyPropertyList([UIPickerView class], &outCount);

    for (i = outCount -1; i >= 0; i--)

    {

        // 循环获取属性的名字   property_getName函数返回一个属性的名称

        NSString *getPropertyName = [NSString stringWithCString:property_getName(pProperty[i]) encoding:NSUTF8StringEncoding];

        NSLog(@"%@",getPropertyName);

        if([getPropertyName isEqualToString:@"textColor"])

        {

//            [_datePicker setValue:[UIColor whiteColor] forKey:@"textColor"];

        }

    }

//        ///修改最大最小时间颜色的BUG
//
//        SEL selector = NSSelectorFromString(@"setHighlightsToday:");
//
//         //NSInvocation;用来包装方法和对应的对象，它可以存储方法的名称，对应的对象，对应的参数,
//
//        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
//
//        BOOL no = NO;
//
//        [invocation setSelector:selector];
//
//        //注意：设置参数的索引时不能从0开始，因为0已经被self占用，1已经被_cmd占用
//
//        [invocation setArgument:&no atIndex:2];
//
//        [invocation invokeWithTarget:_datePicker];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)tanClick:(id)sender {
    [[FMPickerDataView showLinkageTitle:@"联动显示" components:2 items:@[@[@"1", @"2", @"3"], @[@"3", @"3", @"1", @"6"]] componentItems:^NSArray * _Nullable(NSInteger component, id  _Nonnull lastObj) {
        return lastObj;
    } showText:^NSString * _Nullable(NSInteger component, id  _Nonnull obj) {
        if ([obj isKindOfClass:[NSString class]]) {
            return obj;
        } else {
            return @"联动";
        }
    } complete:^(NSArray * _Nonnull selects, NSDictionary * _Nonnull selectRows) {
        
    }] setConfigureShowLabel:^(NSString * _Nonnull showText, UILabel * _Nonnull label, BOOL isSelected) {
//        label.textColor = isSelected ? [UIColor redColor] : [UIColor whiteColor];
    }];
}
- (IBAction)noLinkClick:(id)sender {
    [[FMPickerDataView showTitle:@"不联动" items:@[@[@"1", @"2", @"3"], @[@"3", @"3", @"1", @"6"]] showText:^NSString * _Nullable(NSInteger component, id  _Nonnull obj) {
        return obj;
    } complete:^(NSArray * _Nonnull selects, NSDictionary * _Nonnull selectRows) {
        
    }] showSelectRows:@{@0:@4}];
}
- (IBAction)dateClick:(id)sender {
    [FMDatePickerView showTitle:@"选择日期" dateMode:UIDatePickerModeTime date:[NSDate date] maxDate:nil minDate:nil complete:^(NSDate * _Nonnull date) {
        
    }];
}

- (IBAction)addressClick:(UIButton *)sender {
    NSString *plist = [[NSBundle mainBundle] pathForResource:@"BRCity" ofType:@"plist"];
    [[FMPickerDataView showLinkageTitle:@"地址" components:sender.tag plist:plist componentItems:^NSArray * _Nullable(NSInteger component, id  _Nonnull lastObj) {
        return [lastObj valueForKey:@"n"];
    } showText:^NSString * _Nullable(NSInteger component, id  _Nonnull obj) {
        return [obj valueForKey:@"v"];
    } complete:^(NSArray * _Nonnull selects, NSDictionary * _Nonnull selectRows) {
        
    }] showSelectRows:@{@0:@10,@1:@2,@3:@20}];
}


@end
